# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo3.09
# Description:  循环中的else语句
# Author:       $赵怡蕾
# Date:         2019/1/25
#-------------------------------------------------------------------------------

# import random                               # 导入随机数模块
# x = 0
# break_flag = False                          # 设置是否使用break语句中断循环的标志变量
# while x < 10:
#     x += 1
#     if x == random.randint(1,20):           # 产生一个1到20的随机整数
#         break_flag = True                   # 如果循环中断，将标志设为True
#         print(x)
#         break
#     if not break_flag:                      # 如果标志位False。表示循环是正常退出的
#         print("没有中断while循环")


# 在while和for语句中加上else语句
x = 0
while x < 10:
    x += 1
    if x == random.randint(1,20):
        print(x)
        break
    else:                                   # while循环的else子句
        print("没有中断while循环")

    numbers = [1,2,3,4,5,6]
    for number in numbers:
        if number == random.randint(1,12):
            print(number)
            break
        else:                               # for循环的else子句
            print("正常退出循环")